module namespace order="http://sendmeafilter.com/data/order";

declare boundary-space preserve;
declare option xdmp:mapping "false";

declare variable $exampleOrders :=
<orders>
{
	for $i in 1 to 42	return 
		<order orderid="{fn:concat('F',$i+4376)}">
			<email>bob{$i}@somewhere.com</email>
			<address>
				<line>259 E. 1375 S.</line>
				<city>{ order:rand(('Kaysville','Layton','Farmington','Syracuse','Centerville')) }</city>
				<state>UT</state>
				<zip>{ order:between(84035,84039) }</zip>
			</address>
			<orderStates>
				<orderState id="{ order:rand(('selected')) }" />
			</orderStates>
			<xnextShipping>{(:(fn:current-date() - xs:duration('P30D')) + xs:duration(fn:concat('P',order:between(0,80),'D')):)}</xnextShipping>
			<nextShipping>2012-02-{ order:between(10,28) }</nextShipping>
			<items>
			{
				let $items := (xdmp:random() mod 4) + 1
				for $item in 1 to $items return 
				<item>
					<frequency></frequency>
					<quantity>{ order:rand((1,2,3,4,5,6,7,8)) }</quantity>
					<productId>m8</productId>
					<productName>{ order:rand(('Merv8','Merv11','Carbon')) }</productName>
					<size>
						<height>{ order:rand(('14','16','18','20')) }</height>
						<width>{ order:rand(('20','22','24',25,26)) }</width>
						<thickness>{ order:rand((1,2,5)) }</thickness>
						<search>14x20 14x20x2</search>
					</size>
					<pricePerItem></pricePerItem>
					<payPalLink>{xdmp:random()}</payPalLink>
				</item>
			}
			</items>
			<firstPaymentDate></firstPaymentDate>
			<firstPaymentAmount></firstPaymentAmount>
			<paymentFrequency></paymentFrequency>
			<periodicPaymentAmount></periodicPaymentAmount>
			<subscriptionEndDate></subscriptionEndDate>
		</order>
}
</orders>;

declare function order:rand($items) { let $c := (xdmp:random() mod fn:count($items)) + 1 return $items[$c] };
declare function order:between($start,$end) { let $c := $end - $start return (xdmp:random() mod $c) + $start };

declare function order:create($height,$width,$thickness,$type,$qty,$freq,$state) as element(order) {
	<order>
	</order>
};
			